<?php
namespace app\admin\loglic;

class User
{
    /**
     * 默认字段
     * @param array $data 初始数据 
     * @return array 表单与表格定义的格式
     */
    public function fields($data)
    {
        $fields = [
            'html_1' => [
                'order'           => 0,
                'type'            => 'html',
                'value'           => '<div class="row"><div class="col-12 col-md-8">',
            ],
            'user_id' => [
                'order'           => 1,
                'type'            => 'hidden',
                'value'           => $data['user_id'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-sortable'   => true,
                'data-width'      => 80,
            ],
            'user_name' => [
                'order'           => 2,
                'type'            => 'text',
                'value'           => $data['user_name'],
                'required'        => true,
                'data-filter'     => false,
                'data-visible'    => true,
                'data-escape'     => true,
                'data-align'      => 'left',
            ],
            'user_nice_name' => [
                'order'           => 3,
                'type'            => 'text',
                'value'           => DcEmpty($data['user_nice_name'],uniqid()),
                'data-filter'     => false,
                'data-visible'    => true,
                'data-escape'     => true,
                'data-width'      => 150,
                'data-class'      => 'text-wrap',
                'data-align'      => 'left',
            ],
            'user_slug' => [
                'order'           => 4,
                'type'            => 'text',
                'value'           => $data['user_slug'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'user_pass' => [
                'order'           => 5,
                'type'            => 'password',
                'value'           => $data['user_pass'],
                'data-filter'     => false,
                'data-visible'    => false,
            ],
            'user_email' => [
                'order'           => 6,
                'type'            => 'email',
                'value'           => $data['user_email'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-escape'     => true,
                'data-width'      => 120,
            ],
            'user_mobile' => [
                'order'           => 7,
                'type'            => 'text',
                'value'           => $data['user_mobile'],
                'data-filter'     => false,
                'data-visible'    => true,
                'data-escape'     => true,
                'data-sortable'   => true,
                'data-width'      => 120,
            ],
            'html_2'      => [
                'order'           => 7,
                'type'            => 'html',
                'value'           => '</div><div class="col-12 col-md-4">',
            ],
            'user_status' => [
                'order'           => 8,
                'type'            => 'select',
                'value'           => DcEmpty($data['user_status'],'normal'),
                'option'          => ['normal'=>lang('normal'),'hidden'=>lang('hidden')],
                'data-filter'     => true,
                'data-visible'    => false,
            ],
            'user_status_text' => [
                'order'           => 8,
                'data-title'      => lang('user_status'),
                'data-visible'    => true,
                'data-width'      => 80,
            ],
            'user_create_time' => [
                'order'           => 9,
                'type'            => 'text',
                'value'           => $data['user_create_time'],
                'placeholder'     => '',
                'data-visible'    => true,
                'data-width'      => 120,
                'data-sortable'   => true,
            ],
            'user_update_time' => [
                'order'           => 10,
                'type'            => 'text',
                'value'           => $data['user_update_time'],
                'placeholder'     => '',
                'data-visible'    => true,
                'data-width'      => 120,
                'data-sortable'   => true,
            ],
            'user_create_ip' => [
                'order'           => 11,
                'type'            => 'text',
                'value'           => $data['user_create_ip'],
                'placeholder'     => '',
                'data-visible'    => true,
                'data-width'      => 100,
            ],
            'user_update_ip' => [
                'order'           => 12,
                'type'            => 'text',
                'value'           => $data['user_update_ip'],
                'placeholder'     => '',
                'data-visible'    => true,
                'data-width'      => 100,
            ],
            'user_views' => [
                'order'           => 13,
                'type'            => 'text',
                'value'           => $data['user_views'],
                'placeholder'     => '',
                'data-sortable'   => true,
                'data-visible'    => true,
                'data-width'      => 80,
            ],
            'user_hits' => [
                'order'           => 14,
                'type'            => 'text',
                'value'           => $data['user_hits'],
                'placeholder'     => '',
                'data-sortable'   => true,
                'data-visible'    => true,
                'data-width'      => 80,
            ],
            'user_token' => [
                'order'           => 15,
                'type'            => 'text',
                'value'           => $data['user_token'],
                'placeholder'     => '',
            ],
            'html_3' => [
                'order'           => 999,
                'type'            => 'html',
                'value'           => '</div></div>',
            ]
        ];
        
        //表单扩展字段自动处理
        $fieldExtend = DcFields(config('custom_fields.user_meta'), $data);
        if($fieldExtend){
            $fields = DcArrayPush($fields, $fieldExtend, 'html_2');
        }
        //返回所有表单字段
        return $fields;
    }
}